//
//  NaviCountDownView.m
//  one_buy_guizhou_ios
//
//  Created by xu yao on 2021/2/2.
//  Copyright © 2021 杨帅. All rights reserved.
//

#import "NaviCountDownView.h"
#import "UIView+Extension.h"
#import "CSButton.h"

@interface NaviCountDownView ()


@end

@implementation NaviCountDownView

+ (instancetype)countDownView:(CGPoint)point {
    NaviCountDownView *cView = [[NaviCountDownView alloc] initWithFrame:CGRectMake(point.x, point.y, 180, 50)];
    return cView;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 10;
        self.layer.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.1].CGColor;
        self.layer.shadowOffset = CGSizeMake(0, 0);
        self.layer.shadowRadius = 5;
        self.layer.shadowOpacity = 1;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.countDownLabel];
    [self addSubview:self.timeLabel];
    [self addSubview:self.redGreedIView];
    [self addSubview:self.numberLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.countDownLabel sizeToFit];
    self.countDownLabel.centerX = self.width * 0.5;
    self.countDownLabel.top = 8;
    
    [self.timeLabel sizeToFit];
    self.timeLabel.centerX = self.countDownLabel.centerX;
    self.timeLabel.top = self.countDownLabel.bottom + 5;
    
    [self.redGreedIView sizeToFit];
    self.redGreedIView.centerY = self.countDownLabel.centerY;
    self.redGreedIView.left = self.countDownLabel.right + 5;
    
    [self.numberLabel sizeToFit];
    self.numberLabel.left = self.redGreedIView.right + 2;
    self.numberLabel.centerY = self.redGreedIView.centerY;
    
    self.countDownLabel.centerX -= (self.numberLabel.right - self.redGreedIView.left) * 0.5;
    self.redGreedIView.left = self.countDownLabel.right + 5;
    self.numberLabel.left = self.redGreedIView.right + 2;
}

#pragma 懒加载
-(UILabel *)countDownLabel {
    if (!_countDownLabel) {
        _countDownLabel = [[UILabel alloc] init];
        _countDownLabel.text = @"0公里 0分钟";
        _countDownLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.85];
        _countDownLabel.font = [UIFont systemFontOfSize:15];
    }
    return _countDownLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.text = @"0分钟后到达";
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.45];
    }
    return _timeLabel;
}

- (UIImageView *)redGreedIView {
    if (!_redGreedIView) {
        _redGreedIView = [[UIImageView alloc] init];
        _redGreedIView.image = [UIImage imageNamed:@"icon／路线备份"];
    }
    return _redGreedIView;
}

- (UILabel *)numberLabel {
    if (!_numberLabel) {
        _numberLabel = [[UILabel alloc] init];
        _numberLabel.textColor = [UIColor colorWithWhite:0 alpha:0.85];
        _numberLabel.font = [UIFont systemFontOfSize:12];
    }
    return _numberLabel;
}

@end
